<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 500px;
            height: 500px;
            border: 20px solid orange;
            padding: 50px;
            margin: 30px;
            background-color: green;
        }
    </style>
</head>

<body>
    <div class="box">

    </div>

    <script>
        const box = document.querySelector('.box')

        console.log("Width:", box.offsetWidth);//获取内容的可见宽度，不包含margin
        console.log("Heigth:", box.offsetHeight);

        console.log("Width:", box.clientWidth);//获取内容宽度，只包含padding
        console.log("Heigth:", box.clientHeight);
    </script>
</body>

</html>